package org.example.deadQueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import org.example.RabbitMqUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @BelongsProject: springboot3
 * @BelongsPackage: org.example.deadQueue
 * @Author: guodf
 * @CreateTime: 2024-01-31  10:20
 * @Description:
 * @Version: 1.0.0
 */
public class Consumer2ForDead {

    // 死信队列交换机
    public static final String DEAD_EXCHANGE_NAME = "dead_exchange";
    // 死信队列
    public static final String DEAD_QUEUE_NAME = "dead_queue";

    public static void main(String[] args) throws Exception {
        // 创建连接
        Channel channel = RabbitMqUtils.getChannel();
        System.out.println("消费者2准备接受消息---");
        // 消费者2接受消息回调
        DeliverCallback deliverCallback = (consumerTag, delivery) -> {
            String message = new String(delivery.getBody(), "UTF-8");
            System.out.println("消费者2收到死信消息：" + message);
        };
        channel.basicConsume(DEAD_QUEUE_NAME, true, deliverCallback, consumerTag -> {
        });
    }
}